package com.shitu.base.net.base;

import com.alibaba.fastjson.JSON;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 网络请求回调封装
 * Created by majie on 2017/11/29.
 */

public abstract class BaseCallBack implements Callback<BaseResponse> {
    @Override
    public void onResponse(Call<BaseResponse> call, Response<BaseResponse> response) {
        BaseResponse res = response.body();
        //处理了所有请求不为A00000的情况，此code为与后台约定的访问成功的代码
        onSuccess(call, JSON.toJSONString(res));
    }

    @Override
    public void onFailure(Call call, Throwable throwable) {
        onFail(call, throwable);
    }

    public abstract void onSuccess(Call call, String data);

    public abstract void onFail(Call call, Throwable throwable);
}
